//
//  CTAppLanguage.m
//  Test
//
//  Created by riley on 15/3/17.
//  Copyright (c) 2015年 riley. All rights reserved.
//



#import "CTAppLanguage.h"

static NSBundle * languagesFileBundle = nil;


@implementation CTAppLanguage



//获取当前运行环境语言
+(NSString *)localizedStringForKey:(NSString *)key
                         withValue:(NSString *)value
                         withTable:(NSString *)tableName
{
    NSBundle * bundle = [self localLanguagesProfileBundle];
    NSString * languageStr = [bundle localizedStringForKey:key value:value table:tableName];
    
    return languageStr;
}


//获取系统当前语言环境
+(NSString *)systemLanguage
{
    NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
    NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
    NSString *currentLanguage = [languages objectAtIndex:0];
    
    return currentLanguage;
}

//获取当前语言资源文件
+(NSBundle *)localLanguagesProfileBundle
{
    
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    //简体中文
    [CTAppLanguage setUserlanguage:@"zh-Hans"];
//    if([languageStr isEqualToString:@"en"])
//    {
//        //英文
//        [CTAppLanguage setUserlanguage:@"en"];
//    }
//    else if([languageStr isEqualToString:@"zh-Hans"])
//    {
//        //简体中文
//        [CTAppLanguage setUserlanguage:@"zh-Hans"];
//    }
//    
//    else if([languageStr isEqualToString:@"zh-Hant"] || [languageStr isEqualToString:@"zh-HK"])
//    {
//        //传统繁体中文(Traditional || Hong Kong)
//        [CTAppLanguage setUserlanguage:@"zh-Hant"];
//    }
//    else
//    {
//        //如果是其他语言,默认为英文
//        [CTAppLanguage setUserlanguage:@"en"];
//    }
    
    return languagesFileBundle;
}

//设置当前app语言环境
+(void)setUserlanguage:(NSString *)language
{
    NSString *path = [[NSBundle mainBundle] pathForResource:language ofType:@"lproj" ];
    
    languagesFileBundle = [NSBundle bundleWithPath:path];
}

@end
